//传入武器等级，单位，自动构造武器和弹药
params ["_level", "_unit"];
private ["_one", "_num", "_mags"];

_level = round(_level);
if(_level < 0) then{_level = 0};
if(_level > 4) then{_level = 4};

if(_unit isKindOf "Man") then
{
	switch (_level) do {
		case 0: { _one = selectRandom asw_ai_0; };
		case 1: { _one = selectRandom asw_ai_1; };
		 case 2: { _one = selectRandom asw_ai_2; };
		  case 3: { _one = selectRandom asw_ai_3; };
		   case 4: { _one = selectRandom asw_ai_3; };
		default {};
	};
}
else
{
		switch (_level) do {
		case 0: { _one = selectRandom asw_0; };
		case 1: { _one = selectRandom asw_1; };
		 case 2: { _one = selectRandom asw_2; };
		  case 3: { _one = selectRandom asw_3; };
		   case 4: { _one = selectRandom asw_4; };
		default {};
	};

};


//数量
_num = (_one select 0);
_num = _num * random [0.4, 0.6, 0.8];



_weapon = selectRandom _one;

if(typeName _weapon != "STRING"
|| {getText(configfile >> "CfgWeapons" >> _weapon >> "author") == ""}) then
{
	_weapon = _one select 1;
};



_mags = _weapon call fn_getWeaponMag;
if(_unit isKindOf "Man") then
{
	for "_i" from 1 to _num do
	{
		_unit addMagazineGlobal (selectRandom _mags);//addMagazine的单位必须是本地的
	};
	_unit addWeaponGlobal _weapon;
}
else
{
	//有概率只有弹药，没有武器
	if(random 100 < 66)then{
		_unit addItemCargoGlobal [_weapon, 1];
	};
	
	for "_i" from 1 to _num do
	{
		_unit addItemCargoGlobal [(selectRandom _mags), 1];
	};
};
